using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GridSpawner : MonoBehaviour
{
    public GameObject gridObject;
    private void Start()
    {
        CreateGrids();
    }

    public void CreateGrids()
    {
        for (int rowIndex = 0; rowIndex < GlobalDef.ROW_COUNT; ++rowIndex)
        {
            for (int columIndex = 0; columIndex < GlobalDef.COLUM_COUNT; ++columIndex)
            {
                // 实例化格子物体
                var obj = Instantiate(gridObject);
                obj.transform.SetParent(gridObject.transform.parent, false);
                obj.transform.localPosition = new Vector3((columIndex - GlobalDef.COLUM_COUNT / 2f) * GlobalDef.GRID_SIZE + GlobalDef.GRID_SIZE / 2f, (rowIndex - GlobalDef.ROW_COUNT / 2f) * GlobalDef.GRID_SIZE + GlobalDef.GRID_SIZE / 2f, 0);
            }
        }
        gridObject.SetActive(false);
    }
}
